/* 便捷的方波产生器 */
#ifndef TIMER2_H_INCLUDED
#define TIMER2_H_INCLUDED
#define TC2_CKSTOP	0
#define TC2_CK1		(_BV( CS20) )
#define TC2_CK8		(_BV( CS21 ))
#define TC2_CK64	(_BV( CS21 ) | _BV( CS20 ))
#define TC2_CK256	(_BV( CS22 ))
#define TC2_CK1024	(_BV( CS22 ) | _BV( CS20 ))
#define NR_TC2_CKS  5
#define TC2_CK_BITS (_BV( CS22 ) | _BV( CS21 ) | _BV( CS20 ) )
#define TC2_COMS 	(_BV( COM21) | _BV(COM20) )
extern const Message * const timer2Comp;
/* 初始化 , 默认是处于停止状态的*/
void timer2Init( UINT8 ocr );
static inline void timer2Freq( UINT8 ocr )
{
	OCR2 = ocr;
}
inline INT32 timer2GetCount( void );
inline void timer2SetCount( INT32 cnt );
void timer2SetNotice( INT32 count, MsgBox *mb );
static inline void timer2Stop( void )
{
	UINT8 sr = SREG;
	cli();
	TCCR2 =~ TC2_CK_BITS;/* 保持引角定义不变 */
	SREG = sr;
}
static inline void timer2Start( UINT8 ck )
{
	ck &= TC2_CK_BITS;
	UINT8 sr = SREG;
	cli();
	TCCR2 = ck | _BV(WGM21) | _BV(COM20);
	SREG = sr;
}

#endif /* TIMER2_H_INCLUDED */
